package com.funymmz.demo.service.impl;

import com.funymmz.demo.dao.BabyroomRepository;
import com.funymmz.demo.domain.Babyroom;
import com.funymmz.demo.service.BabyroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BabyroomImplService implements BabyroomService {

    @Autowired
    BabyroomRepository babyroomRepository;

    /**
     * 找到所有母婴室
     * @return 母婴室列表
     */
    public List<Babyroom> findAll() {return babyroomRepository.findAll();}

    /**
     * 分页获取母婴室
     * @param pageable pageable
     * @return 母婴室页
     */
    public Page<Babyroom> findAll(Pageable pageable) {return babyroomRepository.findAll(pageable);}

    /**
     * 带查询的分页
     * @param babyroomExample babyroomExample
     * @param pageable pageable
     * @return Page<Babyroom>
     */
    public Page<Babyroom> findAll(Example<Babyroom> babyroomExample, Pageable pageable){
        return babyroomRepository.findAll(babyroomExample, pageable);
    }

    /**
     * 插入母婴室信息
     * @param babyroom 母婴室
     * @return babyroom
     */
    public Babyroom insert(Babyroom babyroom) {return babyroomRepository.save(babyroom);}

    /**
     * 更新母婴室信息
     * @param babyroom 母婴室
     * @return babyroom
     */
    public Babyroom update(Babyroom babyroom){return babyroomRepository.save(babyroom);}

    /**
     * 删除母婴室
     * @param babyroom 母婴室
     */
    public void delete(Babyroom babyroom){babyroomRepository.delete(babyroom);}

    /**
     * 通过id删除母婴室
     * @param id 母婴室Id号
     */
    public void delete(Long id){
        Babyroom babyroom = new Babyroom();
        babyroom.setId(id);
        babyroomRepository.delete(babyroom);
    }

    /**
     * 通过id获取母婴室
     * @param id 母婴室Id号
     * @return 母婴室
     */
    public Babyroom getById(Long id){return babyroomRepository.findById(id).orElse(null);}

    /**
     * 根据所在商场获取母婴室
     * @param market 商场名称
     * @return 母婴室列表
     */
    public List<Babyroom> findByMarket(String market){return babyroomRepository.findByMarket(market);}
}
